package com.example.agricultural_big_data.service.serviceimpl;

import com.example.agricultural_big_data.mapper.CropMapper;
import com.example.agricultural_big_data.pojo.Crop;
import com.example.agricultural_big_data.pojo.Know;
import com.example.agricultural_big_data.pojo.Plantation;
import com.example.agricultural_big_data.service.CropService;
import com.example.agricultural_big_data.util.DateUtils.DateUtils;
import com.example.agricultural_big_data.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:CropService
 * Package:com.example.agricultural_big_data.service.serviceimpl
 * Description:
 *
 * @Data:2022/5/16 16:03
 */
@Service
public class CropServiceImpl implements CropService {

    @Autowired
    CropMapper cropMapper;

    @Override
    public List<Crop> getCropList(Crop crop) {
        if (crop.getUserId().equals("8e883e8192e643b4a8d4f6d72afa1edd")){
            crop.setUserId("");
            return cropMapper.getCropList(crop);
        }
        return cropMapper.getCropList(crop);
    }

    @Override
    public List<Know> getKnowList(Know know) {
        return cropMapper.getKnowList(know);
    }

    @Override
    public int addCrop(Crop crop) {
        // 生成id
        crop.setCropId(UUIDUtil.randomUUID());
        // 通过作物名称去知识表找到对应数据
        Know know = new Know();
        know.setCropName(crop.getCropName());
        List<Know> knowList = cropMapper.getKnowList(know);
        Know know1 = knowList.get(0);
        crop.setGrowth(know1.getGrowth());
        crop.setTemp(know1.getTemp());
        crop.setHumidity(know1.getHumidity());
        crop.setN(know1.getN());
        crop.setP(know1.getP());
        crop.setK(know1.getK());
        crop.setLight(know1.getLight());
        crop.setPh(know1.getPh());
        crop.setSort(know1.getSort());
        crop.setWind(know1.getWind());
        crop.setCreateTime(DateUtils.getDate());
        return cropMapper.addCrop(crop);
    }
}
